package com.mzj.saas.mservice.property.controller;

import com.mzj.saas.commons.ApiData;
import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.property.service.ServiceUserService;
import com.mzj.saas.mservice.property.vo.ServiceUserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 维修人员管理
 */
@RestController
@RequestMapping("/property/serviceUser")
public class ServiceUserController {
    @Autowired
    private ServiceUserService serviceUserService;

    /**
     * 维修人员列表
     *
     * @param accessToken
     * @param serviceUserName 维修人员姓名
     * @param mobile 维修人电话
     * @param orderNumber 订单id
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping
    public ResultBean<ApiData<ServiceUserVO>> list(@RequestHeader String accessToken,
                                                   @RequestParam(required = false) String serviceUserName,
                                                   @RequestParam(required = false) String mobile,
                                                   @RequestParam(required = false) Integer orderNumber,
                                                   @RequestParam(defaultValue = "0") Integer pageNumber,
                                                   @RequestParam(defaultValue = "5") Integer pageSize) {
        return serviceUserService.list(accessToken, serviceUserName, mobile, orderNumber, pageNumber, pageSize);
    }

    /**
     * 新增/编辑维修人员
     *
     * @param accessToken
     * @param serviceUserVO
     * @return
     */
    @PostMapping
    public ResultBean<ServiceUserVO> save(@RequestHeader String accessToken,
                                          @Valid @RequestBody ServiceUserVO serviceUserVO) {
        return serviceUserService.save(accessToken, serviceUserVO);
    }

    /**
     * 删除维修人员
     *
     * @param accessToken
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResultBean<Object> delete(@RequestHeader String accessToken, @PathVariable Long id) {
        return serviceUserService.delete(accessToken, id);
    }

    /**
     * 维修人员下拉框
     *
     * @param accessToken
     * @return
     */
    @GetMapping("/findServiceUser")
    public ResultBean<List<Map<String, Object>>> findServiceUser(@RequestHeader String accessToken) {
        return serviceUserService.findServiceUser(accessToken);
    }


}
